import random

def do_trials(n):
    hits = [0] * 10
    for i in range(n):
        a = random.randint(0,9)
        hits[a] += 1
    for i in range(10):
        fss = '{}:{}\t {:.3}'
        print(fss.format(i,hits[i],hits[i]/(n/10)))

# do_trials(10)



def play_the_game():
    n = random.randint(1,50)
    while True:
        guess = int(input('Enter guess (0 to exit): '))
        if guess == 0:
            print('Exiting game.')
            break
        elif guess == n:
            print('Success! You win.')
            break
        elif guess < n:
            print('Too low.',end=' ')
        else:
            print('Too high.',end=' ')

while True:
    play_the_game()
    ans = input('Want to play again? (Y or N): ')
    if not ans or ans[0] in 'Nn':
        break



